package com.ita.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ita.entity.User;
import com.ita.service.IUserService;
import com.ita.service.impl.UserServiceImpl;

/**
 * Servlet implementation class ContentServlet
 */
public class ContentServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private IUserService service=new UserServiceImpl();      
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ContentServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		showAll(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		showAll(request,response);
	}
    private void showAll(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
    	HttpSession session=request.getSession();
    	List<User> list=new ArrayList<User>();
    	User user=(User) session.getAttribute("loginToken");
    	if(session.getAttribute("loginToken")!=null){
    		List<User> list1=service.showAllUsers();
    		for(User user1:list1){
    			list.add(user1);
    		}
    	}
		request.setAttribute("list", list);
		request.setAttribute("user", user);
		request.getRequestDispatcher("alluser.jsp").forward(request, response);
    	
	}
}
